“EBImage2 dan Analisis Prediktif”

“Rizka Ma’rifatul Khasanah”

##Instalasi Package

#Install package
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("EBImage")
{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
## Installing package(s) 'EBImage'
## package 'EBImage' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'EBImage'
#panggil package
library(EBImage)
# install.packages("jpeg")
library(jpeg)
setwd("C:/Users/AVITA/Downloads")
library(EBImage)
image <- readImage('Menara.jpeg')
display(image)

hist(image)

display(image, method="browser")
display(image, method="raster")
text(x = 20, y = 20, label = "Menara Prof Dr Imam Suprayogo", adj = c(0,1), col = "black", cex = 2)

#Colour Management
colorMode(image) = Grayscale
display(image, all=TRUE)

colorMat = matrix(rep(c("red","green","#0000ff"), 25), 5, 5)
colorImg = Image(colorMat)
colorImg
## Image 
##   colorMode    : Color 
##   storage.mode : double 
##   dim          : 5 5 3 
##   frames.total : 3 
##   frames.render: 1 
## 
## imageData(object)[1:5,1:5,1]
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    0    0    1    0
## [2,]    0    1    0    0    1
## [3,]    0    0    1    0    0
## [4,]    1    0    0    1    0
## [5,]    0    1    0    0    1
## Image 
##   colorMode    : Color 
##   storage.mode : double 
##   dim          : 5 5 3 
##   frames.total : 3 
##   frames.render: 1 
## 
## imageData(object)[1:5,1:5,1]
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    0    0    1    0
## [2,]    0    1    0    0    1
## [3,]    0    0    1    0    0
## [4,]    1    0    0    1    0
## [5,]    0    1    0    0    1
display(colorImg, interpolate=FALSE)

img_neg = max(image) - image
display( img_neg )
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
img_comb = combine(
  image,
  image + 0.3,
  image * 2,
  image ^ 0.5
)
display(img_comb, all=TRUE)

img_t = transpose(image)
display(img_t)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
img_translate = translate(image, c(100,-50))
display(img_translate)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
img_rotate = rotate(image, 40, bg.col = "blue")
display(img_rotate)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
img_resize = resize(image, w=256, h=256)
display(img_resize )
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
img_flip = flip(image)
img_flop = flop(image)

display(combine(img_flip, img_flop), all=TRUE)

m =  matrix(c(1, -.5, 128, 0, 1, 0), nrow=3, ncol=2)
img_affine = affine(image, m)
display( img_affine )
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
w = makeBrush(size=31, shape='gaussian', sigma=5)
plot(w[nrow(w)+1/2, ], ylab="2", xlab="", cex=0.7)

img_flo = filter2(image, w)
display(img_flo)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
fhi = matrix(1, nrow=3, ncol=3)
fhi[2,2] = -8
img_fhi = filter2(image, fhi)
display(img_fhi)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
l = length(image)
n = l/10
pixels = sample(l, n)
img_noisy = image
img_noisy[pixels] = runif(n, min=0, max=1)
display(img_noisy)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.
img_median = medianFilter(img_noisy, 1)
display(img_median)
## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.

## Only the first frame of the image stack is displayed.
## To display all frames use 'all = TRUE'.